/*******************************************************************************
 * * Copyright 2012 Impetus Infotech.
 *  *
 *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  * you may not use this file except in compliance with the License.
 *  * You may obtain a copy of the License at
 *  *
 *  *      http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 ******************************************************************************/
package cn.ilikes.tools.hbase.jpa.indexs;

import java.util.List;

import org.apache.lucene.index.IndexNotFoundException;

import cn.ilikes.tools.hbase.jpa.clients.nodes.Node;
import cn.ilikes.tools.hbase.jpa.metadatas.IEntityMetaData;

/**
 * Interface to define the behavior of an Indexer.
 * 
 * @author animesh.kumar
 */
public interface Indexer {

	public int INVALID = -1;

	/** The Constant DELIMETER. */
	public static final String DELIMETER = "~";

	/** The Constant ENTITY_ID_FIELD. */
	public static final String ENTITY_ID_FIELD = "entity.id";

	/** The Constant KUNDERA_ID_FIELD. */
	public static final String KUNDERA_ID_FIELD = "hbase.entity.id";

	public static final String KUNDERA_INDEX_TIMESAMP = "jpa.hbase.timestamp";

	/** The Constant ENTITY_INDEXNAME_FIELD. */
	public static final String ENTITY_INDEXNAME_FIELD = "entity.index.name";

	/** The Constant ENTITY_CLASS_FIELD. */
	public static final String ENTITY_CLASS_FIELD = "entity.class";

	public static final String index_fields_null = "null_value";

	/**
	 * auto ; 自动提交 manual 手动
	 * 
	 * @author fack
	 * 
	 */
	public enum FlushType {
		auto, manual
	}

	public void removeById(IEntityMetaData metadata, Object keyId) throws IndexingException;

	public void remove(Node node) throws IndexingException;

	public void removeAllIndexByEntity(Class<?> entityEntiity) throws IndexingException;

	/**
	 * 创建唯一索引
	 * 
	 * @param metadata
	 * @param entity
	 * @throws IndexingException
	 */
	public void create(Node node) throws IndexingException;

	public void index(Node node) throws IndexingException;

	public void update(Node node) throws IndexingException;

	public <V> List<V> search(String luceneQuery, int start, int count, IEntityMetaData metadata, boolean fetchRelation) throws IndexingException;

	public <V> List<V> search(String luceneQuery, int start, int count, IEntityMetaData metadata) throws IndexingException;

	public boolean entityExistsById(Class<?> entityClass, Object keyId) throws IndexingException, IndexNotFoundException;

	public boolean entityExistsByEntity(Node node) throws IndexingException;

	/**
	 * Close on index writer/reader.
	 */
	public void close();

	/**
	 * Flushes out indexes.
	 */
	public void flush();

	public long selectTotalByEntity(Node node) throws IndexingException;

	public long selectTotalByEntityId(Class<?> entityClass, Object keyId) throws IndexingException;
}
